package model

import (
	"github.com/hajimehoshi/ebiten/v2"
	"github.com/hajimehoshi/ebiten/v2/ebitenutil"
	"log"
	"myGame/src/Config"
)

type Live struct {
	Image *ebiten.Image
	X     int
}

func NewLive(screenWidth, screenHeight int) *Live {
	livepng, _, err := ebitenutil.NewImageFromFile("./src/images/live.png")
	if err != nil {
		log.Fatal(err)
	}

	live := &Live{
		Image: livepng,
		X:     0,
	}
	return live
}

// 单独书写一个声明值的方法，方便后续管理
func (live *Live) Draw(screen *ebiten.Image, cfg *Config.Config, r *Realm) {

	op := &ebiten.DrawImageOptions{}
	width, _ := live.Image.Size()
	for i := 0; i < r.Live; i++ {
		op.GeoM.Translate(float64(i*width), 0)
		//fmt.Println(strconv.Itoa(i * width))
		//绘制背景图像
		screen.DrawImage(live.Image, op)
	}

}
